package com.zhc.tools.core.fileimport.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.zhc.tools.core.fileimport.builder.FileStrategyBuilders;
import com.zhc.tools.core.fileimport.domain.FileStrategySetting;

/**
 * 文件上传提供通用服务
 * 
 * @author zhc
 */
@Service("baseUploadFileService")
public class BaseUploadFileService implements IBaseUploadFile {

    protected final Log logger = LogFactory.getLog(this.getClass());
    
    private FileStrategyBuilders fileStrategyBuilders;
    
    @Override
    public List<FileStrategySetting> getFileStrategySettingsByGropyType(String groupType) {
    	if (fileStrategyBuilders != null && StringUtils.isNotBlank(groupType)) {
    		return fileStrategyBuilders.getAll(groupType);
    	}
    	return null;
    }
    
    @Override
    public FileStrategySetting getFileStrategyByTypeKey(String groupType, String strategyServiceType){
    	if (fileStrategyBuilders != null) {
    		return this.fileStrategyBuilders.get(groupType, strategyServiceType);
    	}
    	return null;
    }
    
    @Override
    public FileStrategySetting getFileStrategy(FileStrategySetting fileStrategySetting) {
    	if (fileStrategyBuilders != null && fileStrategyBuilders != null) {
    		return this.getFileStrategyByTypeKey(fileStrategySetting.getGroupType(), fileStrategySetting.getStrategyServiceType());
    	}
    	return null;
    }

	public void setFileStrategyBuilders(FileStrategyBuilders fileStrategyBuilders) {
		this.fileStrategyBuilders = fileStrategyBuilders;
	}
}
